<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/10/6 0006
  Time: 15:37
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>欢迎注册</title>
    <link href="css/register.css" rel="stylesheet">
</head>
<body>

<div class="form-div">
    <div class="reg-content">
        <h1>欢迎注册</h1>
        <span>已有帐号？</span> <a href="login.jsp">登录</a>
    </div>
    <form id="reg-form" action="/javaweb-part03/registerServlet" method="get">

        <table>

            <tr>
                <td>用户名</td>
                <td class="inputs">
                    <input name="username" type="text" id="username">
                    <br>
                    <span id="username_err" class="err_msg">${register_msg}用户名已存在</span>
                </td>

            </tr>

            <tr>
                <td>密码</td>
                <td class="inputs">
                    <input name="password" type="password" id="password">
                    <br>
                    <span id="password_err" class="err_msg" style="display: none">密码格式有误</span>
                </td>
            </tr>


            <tr>
                <td>验证码</td>
                <td class="inputs">
                    <input name="checkCode" type="text" id="checkCode">
                    <img id="checkCodeImage" src="/javaweb-part03/checkCodeServlet" onclick="" style="cursor:pointer">
                    <a href="#" id="changeImg" onclick="">看不清？</a>
                </td>
            </tr>


        </table>

        <div class="buttons">
            <input value="注 册" type="submit" id="reg_btn">
        </div>
        <br class="clear">
    </form>

</div>

<script>

    document.getElementById("changeImg").onclick = function (){
        var milliseconds = new Date().getMilliseconds();
        document.getElementById("checkCodeImage").src = "/javaweb-part03/checkCodeServlet?" + milliseconds;
    }
</script>

<script>
    document.getElementById("checkCodeImage").onclick = function (){
        var milliseconds = new Date().getMilliseconds();
        document.getElementById("checkCodeImage").src = "/javaweb-part03/checkCodeServlet?" + milliseconds;
    }
</script>

<script src="js/axios-0.18.0.js"></script>

<script>
    document.getElementById("username").onblur = function (){
        var username = this.value;


        axios({
            method:"get",
            url:"http://localhost:8080/javaweb-part03/axiosServlet?username=" + username
        }).then(function (resp){
            if(resp.data == true){
                document.getElementById("username_err").style.display = '';
            }else{
                document.getElementById("username_err").style.display = 'none';
            }
        })

    }

</script>

</body>
</html>
